package capaDatos;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import utiles.UIDGenerator;

import capaLogica.PerfilConcurso;
import capaLogica.PerfilFestival;
import capaLogica.PerfilGrupo;
import capaLogica.PerfilSala;

public class PerfilDAO {

	/**
	 * Atributo que crea la conexion a la bd
	 */
	private Connection conn;
	
	/**
	 * Constructor de la clase
	 */
	public PerfilDAO(){
		conn = (Connection) ConnectionManager.getInstance().checkOut();
	}
	
	@Override
	 protected void finalize() {
       ConnectionManager.getInstance().checkIn(conn);
	}
	
	 public PerfilGrupo recuperarPerfilGrupoById(String idPerfil) {
	        PreparedStatement stmt = null;
	        ResultSet result = null;
	        PerfilGrupo p = null;
	        String sql = "SELECT * FROM perfilGrupo WHERE (idPerfilGrupo = ?) ";

	        try {
	            stmt = conn.prepareStatement(sql);
	            stmt.setString(1, idPerfil);
	            result = stmt.executeQuery();

	            if ( result.next() ){
		            p = new PerfilGrupo();
		            p.setIdPerfilGrupo(result.getString("idPerfilGrupo"));
		            p.setNombre(result.getString("nombre"));
		            p.setEmail(result.getString("email"));
		            p.setTelefono(result.getString("telefono"));
		            p.setRider(result.getString("rider"));
		            p.setComponentes(result.getString("componentes"));
	            }
	            
	        } catch (SQLException e) {
	            System.out.println("Message: " + e.getMessage());
	            System.out.println("SQLState: " + e.getSQLState());
	            System.out.println("ErrorCode: " + e.getErrorCode());
	        } finally {
	            try {
	                if (result != null) {
	                    result.close();
	                }
	                if (stmt != null) {
	                    stmt.close();
	                }
	            } catch (SQLException e) {
	            }
	        }
	        return p;
	    }
	 
	 public PerfilSala recuperarPerfilSalaById(String idPerfil) {
	        PreparedStatement stmt = null;
	        ResultSet result = null;
	        PerfilSala p = null;
	        String sql = "SELECT * FROM perfilSala WHERE (idPerfilSala = ?) ";

	        try {
	            stmt = conn.prepareStatement(sql);
	            stmt.setString(1, idPerfil);
	            result = stmt.executeQuery();

	            if ( result.next() ){
		            p = new PerfilSala();
		            p.setIdPerfilSala(result.getString("idPerfilSala"));
		            p.setNombre(result.getString("nombre"));
		            p.setEmail(result.getString("email"));
		            p.setTelefono(result.getString("telefono"));
		            p.setDireccion(result.getString("direccion"));
		            p.setAforoMaximo(result.getInt("aforoMaximo"));
		            p.setCondiconesContratacion(result.getString("condicionesContratacion"));
		            p.setEquipoDisponible(result.getString("equipoDisponibles"));
	            }
	        } catch (SQLException e) {
	            System.out.println("Message: " + e.getMessage());
	            System.out.println("SQLState: " + e.getSQLState());
	            System.out.println("ErrorCode: " + e.getErrorCode());
	        } finally {
	            try {
	                if (result != null) {
	                    result.close();
	                }
	                if (stmt != null) {
	                    stmt.close();
	                }
	            } catch (SQLException e) {
	            }
	        }
	        return p;
	    }
	 
	 public PerfilConcurso recuperarPerfilConcursoById(String idPerfil) {
	        PreparedStatement stmt = null;
	        ResultSet result = null;
	        PerfilConcurso p = null;
	        String sql = "SELECT * FROM perfilConcurso WHERE (idPerfilConcurso = ?) ";

	        try {
	            stmt = conn.prepareStatement(sql);
	            stmt.setString(1, idPerfil);
	            result = stmt.executeQuery();

	            if ( result.next() ){
		            p = new PerfilConcurso();
		            p.setIdPerfilConcurso(result.getString("idPerfilConcurso"));
		            p.setNombre(result.getString("nombre"));
		            p.setEmail(result.getString("email"));
		            p.setTelefono(result.getString("telefono"));
		            p.setInicioConcurso(result.getDate("inicioConcurso"));
		            p.setFinConcurso(result.getDate("finConcurso"));
		            p.setPlazoInscripcion(result.getString("plazoInscripcion"));
		            p.setPrecioInscripcion(result.getInt("precioInscripcion"));
		            p.setPremios(result.getString("premios"));
		            p.setLugar(result.getString("lugar"));
	            }
	            
	        } catch (SQLException e) {
	            System.out.println("Message: " + e.getMessage());
	            System.out.println("SQLState: " + e.getSQLState());
	            System.out.println("ErrorCode: " + e.getErrorCode());
	        } finally {
	            try {
	                if (result != null) {
	                    result.close();
	                }
	                if (stmt != null) {
	                    stmt.close();
	                }
	            } catch (SQLException e) {
	            }
	        }
	        return p;
	    }
	 
	 public PerfilFestival recuperarPerfilFestivalById(String idPerfil) {
	        PreparedStatement stmt = null;
	        ResultSet result = null;
	        PerfilFestival p = null;
	        String sql = "SELECT * FROM perfilFestival WHERE (idPerfilFestival = ?) ";

	        try {
	            stmt = conn.prepareStatement(sql);
	            stmt.setString(1, idPerfil);
	            result = stmt.executeQuery();

	            if ( result.next() ){
		            p = new PerfilFestival();
		            p.setIdPerfilFestival(result.getString("idPerfilFestival"));
		            p.setNombre(result.getString("nombre"));
		            p.setEmail(result.getString("email"));
		            p.setTelefono(result.getString("telefono"));
		            p.setInicioFestival(result.getDate("inicioFestival"));
		            p.setFinFestival(result.getDate("finFestival"));
		            p.setLugar(result.getString("lugar"));
		            p.setCartel(result.getString("cartel"));
		            p.setPrecio(result.getInt("precio"));
		            p.setServiciosFestival(result.getString("serviciosFestival"));
		            p.setCondiciones(result.getString("condiciones"));
	            }
	        } catch (SQLException e) {
	            System.out.println("Message: " + e.getMessage());
	            System.out.println("SQLState: " + e.getSQLState());
	            System.out.println("ErrorCode: " + e.getErrorCode());
	        } finally {
	            try {
	                if (result != null) {
	                    result.close();
	                }
	                if (stmt != null) {
	                    stmt.close();
	                }
	            } catch (SQLException e) {
	            }
	        }
	        return p;
	    }
	 
	 public String recuperarCualquierTipoByID(String idPerfil) {
	        PreparedStatement stmtG = null;
	        PreparedStatement stmtS = null;
	        PreparedStatement stmtF = null;
	        PreparedStatement stmtC = null;
	        ResultSet resultGrupo = null;
	        ResultSet resultSala = null;
	        ResultSet resultFestival = null;
	        ResultSet resultConcurso = null;
	        
	        String nombre = null;
	        String sqlG = "SELECT * FROM perfilGrupo WHERE idPerfilGrupo = ?";
	        String sqlS = "SELECT * FROM perfilSala WHERE idPerfilSala = ?";
	        String sqlF = "SELECT * FROM perfilFestival WHERE idPerfilFestival = ?";
	        String sqlC = "SELECT * FROM perfilConcurso WHERE idPerfilConcurso = ?";

	        try {
	        	// Busqueda en Grupo
	            stmtG = conn.prepareStatement(sqlG);	            
	            stmtG.setString(1, idPerfil);
	            resultGrupo = stmtG.executeQuery();

	            if ( resultGrupo.next() ){
		           nombre = resultGrupo.getString("nombre");
	            }
	            
	         // Busqueda en Sala
	            stmtS = conn.prepareStatement(sqlS);	            
	            stmtS.setString(1, idPerfil);
	            resultSala = stmtS.executeQuery();

	            if ( resultSala.next() ){
		           nombre = resultSala.getString("nombre");
	            }
	            
	            // Busqueda en Festival
	            stmtF = conn.prepareStatement(sqlF);	            
	            stmtF.setString(1, idPerfil);
	            resultFestival = stmtF.executeQuery();

	            if ( resultFestival.next() ){
		           nombre = resultFestival.getString("nombre");
	            }
	            
	            // Busqueda en Concurso
	            stmtC = conn.prepareStatement(sqlC);	            
	            stmtC.setString(1, idPerfil);
	            resultConcurso = stmtC.executeQuery();

	            if ( resultConcurso.next() ){
		           nombre = resultConcurso.getString("nombre");
	            }
	        } catch (SQLException e) {
	            System.out.println("Message: " + e.getMessage());
	            System.out.println("SQLState: " + e.getSQLState());
	            System.out.println("ErrorCode: " + e.getErrorCode());
	        } finally {
	            try {
	                if (resultGrupo != null) {
	                    resultGrupo.close();
	                }
	                if (stmtG != null) {
	                    stmtG.close();
	                }
	                if (resultSala != null) {
	                    resultSala.close();
	                }
	                if (stmtS != null) {
	                    stmtS.close();
	                }
	                if (resultFestival != null) {
	                    resultFestival.close();
	                }
	                if (stmtF != null) {
	                    stmtF.close();
	                }
	                if (resultConcurso != null) {
	                    resultConcurso.close();
	                }
	                if (stmtC != null) {
	                    stmtC.close();
	                }
	            } catch (SQLException e) {
	            }
	        }
	        return nombre;
	    }
	 
	 public void actualizarPerfilGrupo(PerfilGrupo p) {
			String sql = "UPDATE perfilGrupo SET nombre = ?, email = ?, telefono = ?, rider = ?, componentes = ?  WHERE (idPerfilGrupo = ?)";
			PreparedStatement stm = null;
			try {
				
				stm = conn.prepareStatement(sql);
				stm.setString(1, p.getNombre());
				stm.setString(2, p.getEmail());
				stm.setString(3, p.getTelefono());
				stm.setString(4, p.getRider());
				stm.setString(5, p.getComponentes());
				stm.setString(6, p.getIdPerfilGrupo());
				stm.executeUpdate();

			} catch (SQLException e) {
				System.out.println("Message: " + e.getMessage());
				System.out.println("SQLState: " + e.getSQLState());
				System.out.println("ErrorCode: " + e.getErrorCode());
			} finally {
				try {
					if (stm != null) {
						stm.close();
					}
				} catch (SQLException e) {

				}
			}
		}
	 
	 public void actualizarPerfilSala(PerfilSala p) {
			String sql = "UPDATE perfilSala SET nombre = ?, email = ?, telefono = ?, direccion = ?, aforoMaximo = ?, condicionesContratacion = ?, equipoDisponible = ?  WHERE (idPerfilSala = ?)";
			PreparedStatement stm = null;
			try {
				
				stm = conn.prepareStatement(sql);
				stm.setString(1, p.getNombre());
				stm.setString(2, p.getEmail());
				stm.setString(3, p.getTelefono());
				stm.setString(4, p.getDireccion());
				stm.setInt(5, p.getAforoMaximo());
				stm.setString(6, p.getCondiconesContratacion());
				stm.setString(7, p.getEquipoDisponible());
				stm.setString(8, p.getIdPerfilSala());
				
				stm.executeUpdate();

			} catch (SQLException e) {
				System.out.println("Message: " + e.getMessage());
				System.out.println("SQLState: " + e.getSQLState());
				System.out.println("ErrorCode: " + e.getErrorCode());
			} finally {
				try {
					if (stm != null) {
						stm.close();
					}
				} catch (SQLException e) {

				}
			}
		}
	 
	 public void actualizarPerfilConcurso(PerfilConcurso p) {
			String sql = "UPDATE perfilConcurso SET nombre = ?, email = ?, telefono = ?, inicioConcurso = ?, finConcurso = ?, plazoInscripcion = ?, precioInscripcion = ?, premios = ?, lugar = ?  WHERE (idPerfilConcurso = ?)";
			PreparedStatement stm = null;
			try {
				
				stm = conn.prepareStatement(sql);
				stm.setString(1, p.getNombre());
				stm.setString(2, p.getEmail());
				stm.setString(3, p.getTelefono());
				stm.setDate(4, (java.sql.Date) p.getInicioConcurso());
				stm.setDate(5, (java.sql.Date) p.getFinConcurso());
				stm.setString(6, p.getPlazoInscripcion());
				stm.setInt(7, p.getPrecioInscripcion());
				stm.setString(8, p.getPremios());
				stm.setString(9, p.getLugar());
				stm.setString(10, p.getIdPerfilConcurso());
				
				stm.executeUpdate();

			} catch (SQLException e) {
				System.out.println("Message: " + e.getMessage());
				System.out.println("SQLState: " + e.getSQLState());
				System.out.println("ErrorCode: " + e.getErrorCode());
			} finally {
				try {
					if (stm != null) {
						stm.close();
					}
				} catch (SQLException e) {

				}
			}
		}
	 
	 public void actualizarPerfilFestival(PerfilFestival p) {
			String sql = "UPDATE perfilConcurso SET nombre = ?, email = ?, telefono = ?, inicioFestival = ?, finFestival = ?, lugar = ?, cartel = ?, precio = ?, serviciosFestival = ?, condiciones = ?  WHERE (idPerfilFestival = ?)";
			PreparedStatement stm = null;
			try {
				
				stm = conn.prepareStatement(sql);
				stm.setString(1, p.getNombre());
				stm.setString(2, p.getEmail());
				stm.setString(3, p.getTelefono());
				stm.setDate(4, new java.sql.Date(p.getInicioFestival().getTime()));
				stm.setDate(5, new java.sql.Date(p.getFinFestival().getTime()));
				stm.setString(6, p.getLugar());
				stm.setString(7, p.getCartel());
				stm.setInt(8, p.getPrecio());
				stm.setString(9, p.getServiciosFestival());
				stm.setString(10, p.getCondiciones());
				stm.setString(11, p.getIdPerfilFestival());
				
				stm.executeUpdate();

			} catch (SQLException e) {
				System.out.println("Message: " + e.getMessage());
				System.out.println("SQLState: " + e.getSQLState());
				System.out.println("ErrorCode: " + e.getErrorCode());
			} finally {
				try {
					if (stm != null) {
						stm.close();
					}
				} catch (SQLException e) {

				}
			}
		}
	 
	 public PerfilGrupo insertarPerfilGrupo(PerfilGrupo user) {
			String sql = "INSERT INTO perfilGrupo (idPerfilGrupo,nombre,email,telefono,rider,componentes) VALUES (?,?,?,?,?,?) ";
			PreparedStatement stmt = null;
			
			try {
				stmt = conn.prepareStatement(sql);
				user.setIdPerfilGrupo(UIDGenerator.getInstance().getKey());
				
				stmt.setString(1, user.getIdPerfilGrupo());
				stmt.setString(2, user.getNombre());
				stmt.setString(3, user.getEmail());
				stmt.setString(4, user.getTelefono());
				stmt.setString(5, user.getRider());
				stmt.setString(6, user.getComponentes());
			
				stmt.executeUpdate();

			} catch (SQLException e) {
				System.out.println("Message: " + e.getMessage());
				System.out.println("SQLState: " + e.getSQLState());
				System.out.println("ErrorCode: " + e.getErrorCode());
			} finally {
				try {
					if (stmt != null) {
						stmt.close();
						
					}
				} catch (SQLException e) {
				}
			}
			
			return user;
		}
	 
	 public PerfilSala insertarPerfilSala(PerfilSala user) {
			String sql = "INSERT INTO perfilSala (idPerfilSala,nombre,email,telefono,direccion,aforoMaximo,condicionesContratacion,equipoDisponibles) VALUES (?,?,?,?,?,?,?,?) ";
			PreparedStatement stmt = null;
			
			try {
				stmt = conn.prepareStatement(sql);
				user.setIdPerfilSala(UIDGenerator.getInstance().getKey());
				
				stmt.setString(1, user.getIdPerfilSala());
				stmt.setString(2, user.getNombre());
				stmt.setString(3, user.getEmail());
				stmt.setString(4, user.getTelefono());
				stmt.setString(5, user.getDireccion());
				stmt.setInt(6, user.getAforoMaximo());
				stmt.setString(7, user.getCondiconesContratacion());
				stmt.setString(8, user.getEquipoDisponible());
			
				stmt.executeUpdate();

			} catch (SQLException e) {
				System.out.println("Message: " + e.getMessage());
				System.out.println("SQLState: " + e.getSQLState());
				System.out.println("ErrorCode: " + e.getErrorCode());
			} finally {
				try {
					if (stmt != null) {
						stmt.close();
						
					}
				} catch (SQLException e) {
				}
			}
			
			return user;
		}
	 
	 public PerfilFestival insertarPerfilFestival(PerfilFestival user) {
			String sql = "INSERT INTO perfilFestival (idPerfilFestival,nombre,email,telefono,inicioFestival,finFestival,lugar,cartel,precio,serviciosFestival,condiciones) VALUES (?,?,?,?,?,?,?,?,?,?,?) ";
			PreparedStatement stmt = null;
			
			try {
				stmt = conn.prepareStatement(sql);
				user.setIdPerfilFestival(UIDGenerator.getInstance().getKey());
				
				java.util.Date inicioFestival= user.getInicioFestival();
	            java.util.Date finFestival = user.getFinFestival();
	            
				stmt.setString(1, user.getIdPerfilFestival());
				stmt.setString(2, user.getNombre());
				stmt.setString(3, user.getEmail());
				stmt.setString(4, user.getTelefono());
				stmt.setDate(5, new java.sql.Date(inicioFestival.getTime()));
				stmt.setDate(6, new java.sql.Date(finFestival.getTime()));
				stmt.setString(7, user.getLugar());
				stmt.setString(8, user.getCartel());
				stmt.setInt(9, user.getPrecio());
				stmt.setString(10, user.getServiciosFestival());
				stmt.setString(11, user.getCondiciones());
			
				stmt.executeUpdate();

			} catch (SQLException e) {
				System.out.println("Message: " + e.getMessage());
				System.out.println("SQLState: " + e.getSQLState());
				System.out.println("ErrorCode: " + e.getErrorCode());
			} finally {
				try {
					if (stmt != null) {
						stmt.close();
						
					}
				} catch (SQLException e) {
				}
			}
			
			return user;
		}
	 
	 public PerfilConcurso insertarPerfilConcurso(PerfilConcurso user) {
			String sql = "INSERT INTO perfilConcurso (idPerfilConcurso,nombre,email,telefono,inicioConcurso,finConcurso,plazoInscripcion,precioInscripcion,premios,lugar) VALUES (?,?,?,?,?,?,?,?,?,?) ";
			PreparedStatement stmt = null;
			
			try {
				stmt = conn.prepareStatement(sql);
				user.setIdPerfilConcurso(UIDGenerator.getInstance().getKey());
				
				java.util.Date inicioConcurso= user.getInicioConcurso();
	            java.util.Date finConcurso = user.getFinConcurso();
	            
				stmt.setString(1, user.getIdPerfilConcurso());
				stmt.setString(2, user.getNombre());
				stmt.setString(3, user.getEmail());
				stmt.setString(4, user.getTelefono());
				stmt.setDate(5, new java.sql.Date(inicioConcurso.getTime()));
				stmt.setDate(6, new java.sql.Date(finConcurso.getTime()));
				stmt.setString(7, user.getPlazoInscripcion());
				stmt.setInt(8, user.getPrecioInscripcion());
				stmt.setString(9, user.getPremios());
				stmt.setString(10, user.getLugar());
			
				stmt.executeUpdate();

			} catch (SQLException e) {
				System.out.println("Message: " + e.getMessage());
				System.out.println("SQLState: " + e.getSQLState());
				System.out.println("ErrorCode: " + e.getErrorCode());
			} finally {
				try {
					if (stmt != null) {
						stmt.close();
						
					}
				} catch (SQLException e) {
				}
			}
			
			return user;
		}

	 public void borrarPerfilGrupo(String idPerfil){
			PreparedStatement stm = null;
			String sql = "DELETE FROM perfilGrupo WHERE (idPerfilGrupo = ?)";
			try {
				stm = conn.prepareStatement(sql);
				stm.setString(1, idPerfil);
				stm.executeUpdate();
			} catch (SQLException e) {
				System.out.println("SQLMessage: " + e.getMessage());
				System.out.println("SQLState: " + e.getSQLState());
				System.out.println("ErrorCode: " + e.getErrorCode());
			} finally {
				try {
					if (stm != null) {
						stm.close();
					}
				} catch (SQLException e) {

				}
			}
		}	
	 
	 public void borrarPerfilSala(String idPerfil) {
			PreparedStatement stm = null;
			String sql = "DELETE FROM perfilSala WHERE (idPerfilSala = ?)";
			try {
				stm = conn.prepareStatement(sql);
				stm.setString(1, idPerfil);

				stm.executeUpdate();
			} catch (SQLException e) {
				System.out.println("SQLMessage: " + e.getMessage());
				System.out.println("SQLState: " + e.getSQLState());
				System.out.println("ErrorCode: " + e.getErrorCode());
			} finally {
				try {
					if (stm != null) {
						stm.close();
					}
				} catch (SQLException e) {

				}
			}
		}	
	 
	 public void borrarPerfilFestival(String idPerfil) {
			PreparedStatement stm = null;
			String sql = "DELETE FROM perfilFestival WHERE (idPerfilFestival = ?)";
			try {
				stm = conn.prepareStatement(sql);
				stm.setString(1, idPerfil);

				stm.executeUpdate();
			} catch (SQLException e) {
				System.out.println("SQLMessage: " + e.getMessage());
				System.out.println("SQLState: " + e.getSQLState());
				System.out.println("ErrorCode: " + e.getErrorCode());
			} finally {
				try {
					if (stm != null) {
						stm.close();
					}
				} catch (SQLException e) {

				}
			}
		}	
	 
	 public void borrarPerfilConcurso(String idPerfil) {
			PreparedStatement stm = null;
			String sql = "DELETE FROM perfilConcurso WHERE (idPerfilConcurso = ?)";
			try {
				stm = conn.prepareStatement(sql);
				stm.setString(1, idPerfil);

				stm.executeUpdate();
			} catch (SQLException e) {
				System.out.println("SQLMessage: " + e.getMessage());
				System.out.println("SQLState: " + e.getSQLState());
				System.out.println("ErrorCode: " + e.getErrorCode());
			} finally {
				try {
					if (stm != null) {
						stm.close();
					}
				} catch (SQLException e) {

				}
			}
		}	
	 
	 public List<PerfilGrupo> recuperarPerfilGrupoByNombre(String idPerfil) {
	        PreparedStatement stmt = null;
	        ResultSet result = null;
	        List<PerfilGrupo> lista = new ArrayList<PerfilGrupo>();
	        String sql = "SELECT * FROM perfilGrupo WHERE (nombre = ?) ";

	        try {
	            stmt = conn.prepareStatement(sql);
	            stmt.setString(1, idPerfil);
	            result = stmt.executeQuery();

	            while ( result.next() ){
	            	PerfilGrupo p = new PerfilGrupo();
		            p = new PerfilGrupo();
		            p.setIdPerfilGrupo(result.getString("idPerfilGrupo"));
		            p.setNombre(result.getString("nombre"));
		            p.setEmail(result.getString("email"));
		            p.setTelefono(result.getString("telefono"));
		            p.setRider(result.getString("rider"));
		            p.setComponentes(result.getString("componentes"));
		            lista.add(p);
	            }
	            
	        } catch (SQLException e) {
	            System.out.println("Message: " + e.getMessage());
	            System.out.println("SQLState: " + e.getSQLState());
	            System.out.println("ErrorCode: " + e.getErrorCode());
	        } finally {
	            try {
	                if (result != null) {
	                    result.close();
	                }
	                if (stmt != null) {
	                    stmt.close();
	                }
	            } catch (SQLException e) {
	            }
	        }
	        return lista;
	    }
	 
	 public List<PerfilSala> recuperarPerfilSalaByNombre(String idPerfil) {
	        PreparedStatement stmt = null;
	        ResultSet result = null;
	        List<PerfilSala> lista = new ArrayList<PerfilSala>();
	        String sql = "SELECT * FROM perfilSala WHERE (nombre = ?) ";

	        try {
	            stmt = conn.prepareStatement(sql);
	            stmt.setString(1, idPerfil);
	            result = stmt.executeQuery();

	            while( result.next() ){
	            	PerfilSala p = null;
		            p = new PerfilSala();
		            p.setIdPerfilSala(result.getString("idPerfilSala"));
		            p.setNombre(result.getString("nombre"));
		            p.setEmail(result.getString("email"));
		            p.setTelefono(result.getString("telefono"));
		            p.setDireccion(result.getString("direccion"));
		            p.setAforoMaximo(result.getInt("aforoMaximo"));
		            p.setCondiconesContratacion(result.getString("condicionesContratacion"));
		            p.setEquipoDisponible(result.getString("equipoDisponibles"));
		            lista.add(p);
	            }
	        } catch (SQLException e) {
	            System.out.println("Message: " + e.getMessage());
	            System.out.println("SQLState: " + e.getSQLState());
	            System.out.println("ErrorCode: " + e.getErrorCode());
	        } finally {
	            try {
	                if (result != null) {
	                    result.close();
	                }
	                if (stmt != null) {
	                    stmt.close();
	                }
	            } catch (SQLException e) {
	            }
	        }
	        return lista;
	    }
	 
	 public List<PerfilConcurso> recuperarPerfilConcursoByNombre(String idPerfil) {
	        PreparedStatement stmt = null;
	        ResultSet result = null;
	        List<PerfilConcurso> lista = new ArrayList<PerfilConcurso>();
	        String sql = "SELECT * FROM perfilConcurso WHERE (nombre = ?) ";

	        try {
	            stmt = conn.prepareStatement(sql);
	            stmt.setString(1, idPerfil);
	            result = stmt.executeQuery();

	            while( result.next() ){
	            	PerfilConcurso p = null;
		            p = new PerfilConcurso();
		            p.setIdPerfilConcurso(result.getString("idPerfilConcurso"));
		            p.setNombre(result.getString("nombre"));
		            p.setEmail(result.getString("email"));
		            p.setTelefono(result.getString("telefono"));
		            p.setInicioConcurso(result.getDate("inicioConcurso"));
		            p.setFinConcurso(result.getDate("finConcurso"));
		            p.setPlazoInscripcion(result.getString("plazoInscripcion"));
		            p.setPrecioInscripcion(result.getInt("precioInscripcion"));
		            p.setPremios(result.getString("premios"));
		            p.setLugar(result.getString("lugar"));
		            lista.add(p);
	            }
	            
	        } catch (SQLException e) {
	            System.out.println("Message: " + e.getMessage());
	            System.out.println("SQLState: " + e.getSQLState());
	            System.out.println("ErrorCode: " + e.getErrorCode());
	        } finally {
	            try {
	                if (result != null) {
	                    result.close();
	                }
	                if (stmt != null) {
	                    stmt.close();
	                }
	            } catch (SQLException e) {
	            }
	        }
	        return lista;
	    }
	 
	 public List<PerfilFestival> recuperarPerfilFestivalByNombre(String idPerfil) {
	        PreparedStatement stmt = null;
	        ResultSet result = null;
	        List<PerfilFestival> lista = new ArrayList<PerfilFestival>();
	        String sql = "SELECT * FROM perfilFestival WHERE (nombre = ?) ";

	        try {
	            stmt = conn.prepareStatement(sql);
	            stmt.setString(1, idPerfil);
	            result = stmt.executeQuery();

	            while( result.next() ){
	            	PerfilFestival p = null;
		            p = new PerfilFestival();
		            p.setIdPerfilFestival(result.getString("idPerfilFestival"));
		            p.setNombre(result.getString("nombre"));
		            p.setEmail(result.getString("email"));
		            p.setTelefono(result.getString("telefono"));
		            p.setInicioFestival(result.getDate("inicioFestival"));
		            p.setFinFestival(result.getDate("finFestival"));
		            p.setLugar(result.getString("lugar"));
		            p.setCartel(result.getString("cartel"));
		            p.setPrecio(result.getInt("precio"));
		            p.setServiciosFestival(result.getString("serviciosFestival"));
		            p.setCondiciones(result.getString("condiciones"));
		            lista.add(p);
	            }
	        } catch (SQLException e) {
	            System.out.println("Message: " + e.getMessage());
	            System.out.println("SQLState: " + e.getSQLState());
	            System.out.println("ErrorCode: " + e.getErrorCode());
	        } finally {
	            try {
	                if (result != null) {
	                    result.close();
	                }
	                if (stmt != null) {
	                    stmt.close();
	                }
	            } catch (SQLException e) {
	            }
	        }
	        return lista;
	    }

}
